package de.dfki.asr.genesis2.sms.util;

public class BoundingBox {
	private double north;
	private double south;
	private double east;
	private double west;
    
    BoundingBox (final int x, final int y, final int zoom) {
    	this.north = tile2lat(y, zoom);
    	this.south = tile2lat(y + 1, zoom);
    	this.west = tile2lon(x, zoom);
    	this.east = tile2lon(x + 1, zoom);
    }
    
    /*
    static String getTileNumber(final double lat, final double lon, final int zoom) {
 	   int xtile = (int)Math.floor( (lon + 180) / 360 * (1<<zoom) ) ;
 	   int ytile = (int)Math.floor( (1 - Math.log(Math.tan(Math.toRadians(lat)) + 1 / Math.cos(Math.toRadians(lat))) / Math.PI) / 2 * (1<<zoom) ) ;
 	    return("" + zoom + "/" + xtile + "/" + ytile);
    }*/
    
    static double tile2lon(int x, int z) {
        return x / Math.pow(2.0, z) * 360.0 - 180;
     }
    
     static double tile2lat(int y, int z) {
       double n = Math.PI - (2.0 * Math.PI * y) / Math.pow(2.0, z);
       return Math.toDegrees(Math.atan(Math.sinh(n)));
     }
    
    double getNorth() {
    	return this.north;
    }
    
    double getSouth() {
    	return this.south;
    }
    
    double getEast() {
    	return this.east;
    }
    
    double getWest() {
    	return this.west;
    }
    
    //Get Bounding box as Comma Separated Values at the following order: South, West, North, East
    String getSWNECSV() {
    	return this.south + "," + this.west + "," + this.north + "," + this.east;
    }
    /*
    double getCenter() {
    	return
    }
    */
    
}


